<template>
  <div class="header">
    <div class="header-md header-wrapper" :class="{'header-show':headerShow || homeSorllShow || params.notHome}" @mouseenter="toggleHeader(1)" @mouseleave="toggleHeader(0)">
      <div class="container-md d-flex align-items-center justify-content-between" style="height:100%">
        <div class="blog-logo" @click="$router.push('/')">
          <img :src="[headerShow||homeSorllShow||params.notHome ? logoSrc[1] : logoSrc[0]]" alt="logo">
        </div>
        <ul class="nav">
          <li class="nav-item" v-for="(item,index) in navList" :key="index">
            <nuxt-link :to="item.path">
              <span class="iconfont" :class="item.iconClass"></span>
                {{item.title}}
              <span class="line"></span>
            </nuxt-link>
          </li>
        </ul>
        <div class="search">
          <b-form-input v-model="keyword" placeholder="搜索"></b-form-input>
          <b-icon icon="search" variant="drak"></b-icon>
        </div>
      </div>
    </div>
    <div class="header-sm header-wrapper">
      <div class="header-sm-nav">
        <div class="blog-logo">
          <img :src="logoSrc[1]" alt="logo">
        </div>
        <b-icon class="icon-menu" icon="list" variant="dark" @click="toggleMenus(1)"></b-icon>
      </div>
      <div class="sidebar-menus" :class="{'show-menu':MenusShow}">
        <div class="avator">
          <img src="https://portrait.gitee.com/uploads/avatars/user/1801/5404644_kailin0_1581229642.png!avatar200" alt="KAIUP">
        </div>
        <ul class="siteList">
          <li v-for="(item,index) in siteList" :key="index">
            <nuxt-link :to="item.path">
              <div>{{item.title}}</div>
              <span>{{item.num}}</span>
            </nuxt-link>
          </li>
        </ul>
        <hr/>
        <ul class="menus">
          <li class="menus-item" v-for="(item,index) in navList" :key="index">
            <nuxt-link :to="item.path">
              <span class="iconfont mr-3" :class="item.iconClass"></span>
              {{item.title}}
            </nuxt-link>
          </li>
        </ul>
      </div>
      <div class="mask" :class="{'show-mask':MenusShow}" @click="toggleMenus(0)"></div>
    </div>
    <div class="nt-header-bg" v-if="params.notHome">
      <h1 class="main-title">{{params.pageTitle}}</h1>
    </div>
    <div v-else class="transtion-bg">
      <div class="img-mask"></div>
      <div class="home-fixedBg">
        <span class="icon-show-more iconfont icon-xiangxia" @click="moveDown"></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    headerInfo:{
      type:Object,
      default:()=>{
        return {}
      }
    },
    homeSorllShow:Boolean
  },
  data() {
    return {
      logoSrc:[require('~/static/img/logo.png'),require('~/static/img/logo_active.png')],
      MenusShow:false,
      headerShow:false,
      navList:[{
      id:0,
      title:'首页',
      path:'/',
      iconClass:'icon-shouye'
      },{
        id:1,
        title:'归档',
        path:'/archive',
        iconClass:'icon-baoguo_shouna'
      },{
        id:2,
        title:'分类',
        path:'/categories',
        iconClass:'icon-24gf-folderOpen'
      },{
        id:3,
        title:'项目',
        path:'/project',
        iconClass:'icon-daima'
      },{
        id:4,
        title:'关于',
        path:'/about',
        iconClass:'icon-OA-toher-1'
      }],
      siteList:[{
        title:'文章',
        num:10,
        path:'#'
      },{
        title:'分类',
        num:4,
        path:'#'
      },{
        title:'标签',
        num:9,
        path:'#'
      }],
      keyword:''
    }
  },
  mounted() {
    this.openScroll()
  },
  computed:{
    params(){ 
        return Object.assign({
            notHome:true,
            pageTitle:''
        },this.headerInfo);
    }
 },
  methods: {
    toggleMenus(bool) {
      if(bool) {
        this.MenusShow = true
        document.querySelector('body').style.overflow = 'hidden'
      }else {
        this.openScroll()
        this.MenusShow = false
      }
    },
    toggleHeader(bool) {
      // 判断移动端不执行
      if(this.params.notHome || this.homeSorllShow) return
      if(bool) {
        this.headerShow = true
      }else {
        this.headerShow = false
      }
    },
    openScroll() {
      document.querySelector('body').style = ''
    },
    moveDown() {
      let clientHeight = document.documentElement.clientHeight
      let contentTopHeight = clientHeight - 75  // 判断移动端 -60
      console.log(clientHeight,contentTopHeight);
      document.body.scrollTop = document.documentElement.scrollTop =  contentTopHeight
    }
  }
}
</script>

<style>
  .header {
    animation: fadeInDown 1s;
  }
  .header-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99;
    background-color: var(--theme-color);
    box-shadow: 0 5px 6px -5px rgb(133 133 133 / 60%);
    transition: all .6s;
    user-select: none;
  }
  .header-md {
    height: 75px;
    background: transparent;
    box-shadow:none;
  }
  .nt-header-bg {
    position: relative;
    height: 25rem;
    background-color: var(--primary);
    transition: all .5s;
  }
  .main-title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    color: #fff;
    font-size: 1.9rem;
    font-weight: bold;
    margin: 0;
    text-shadow: 0.1rem 0.1rem 0.2rem rgb(0 0 0 / 15%);
  }
  .blog-logo {
    cursor: pointer;
    transition: all .3s;
  }
  .nav {
    display: none;
  }
  .nav .nav-item {
    line-height: 75px;
    margin: 0 1rem;
  }
  .nav .nav-item a {
    position: relative;
    font-size: 1rem;
    color: var(--minor-text-color);
    transition: all .3s;
  }
  .nav .nav-item a .line {
    position: absolute;
    bottom: -27px;
    left: 0;
    height: 4px;
    width: 0;
    background-color: var(--primary);
  }
  .nav .nav-item a span {
    transition: all .3s;
    color: var(--minor-text-color);
  }
  .nav .nav-item a:hover {
    color:var(--primary)
  }
  .nav .nav-item a:hover span {
    color:var(--primary)
  }
  .nav .nav-item a:hover .line {
    animation: stretch .3s forwards;
  }
  .nav .nav-item .nuxt-link-exact-active.nuxt-link-active {
    color:var(--primary);
  }
  .nav .nav-item .nuxt-link-exact-active.nuxt-link-active span {
    color: var(--primary);
  }
  .search {
    display: none;
    width: 209px;
    position: relative;
  }
  .search .form-control {
    height: 30px;
    font-size: 15px;
    padding: 0 40px 0 12px;
    border-radius: 20px;
    border: 1px solid #ccc;
    box-shadow: none;
  }
  .search .form-control:focus {
    box-shadow: none;
  }
  .bi-search {
    position: absolute;
    top: 7px;
    right: 13px;
    cursor: pointer;
  }
  .transtion-bg {
    background-image: url('~/static/img/dot.gif');
    width: 100%;
    height: 100vh;
    position:relative;
  }
  .img-mask {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0,0,0,.5);
    z-index: 9;
  }
  .home-fixedBg {
    width: 100%;
    height: 100vh;
    background-image: url('~/static/img/cover.jpg');
    background-size: cover;
    background-position: center center;
    background-repeat:no-repeat;
    background-attachment:fixed;
    position:relative;
  }
  .home-fixedBg .icon-show-more {
    font-size: 25px;
    color: #fff;
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translate(-50%,0);
    animation: float 2s linear infinite;
    cursor: pointer;
  }
  /* 移动端头部 */
  .header-sm {
    display: none;
    height: 60px;
  }
  .icon-menu {
    font-size: 28px;
    cursor: pointer;
    color: var(--base-text-color)!important;
  }
  .header-sm .blog-logo img {
    height: 33px;
    width: auto;
  }
  .header-sm-nav {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
  }
  .sidebar-menus {
    width: 280px;
    height: 100vh;
    position: absolute;
    top: 0;
    right: -280px;
    background-color: var(--theme-color);
    z-index: 11;
    transition: all .6s;
  }
  .sidebar-menus .siteList {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-bottom: 5px;
  }
  .siteList li {
    text-align: center;
  }
  .siteList li a {
    color: var(--minor-text-color);
  }
  .siteList li a>span {
    font-size: 1.25rem;
  }
  .sidebar-menus .avator {
    padding: 25px;
    text-align: center;
  }
  .sidebar-menus .avator img {
    width: 98px;
    height: 98px;
    border-radius: 50%;
    box-shadow: 0 0 2px 3px #9195A1;
  }
  .sidebar-menus hr {
    border: 2px dashed #a4d8fa;
  }
  .menus {
    padding: 15px 38px;
  }
  .menus .menus-item {
    margin-bottom: 1.15rem;
  }
  .menus .menus-item a {
    font-size: 1.15rem;
    color: var(--minor-text-color);
  }
  .mask {
    display: none;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background-color: rgba(0,0,0,.6);
    transition: all .6s;
  }
  .show-menu {
    right: 0;
  }
  .show-mask {
    display: block;
  }

  /* 显示导航栏 */
  .header-show {
    background-color: var(--theme-color);
    box-shadow: 0 5px 6px -5px rgb(133 133 133 / 60%);
  }
  .header-show .nav {
    display: flex;
    animation: fadeInRight 1s;
  }
  .header-show .search{
    display: block;
  }
  /* 显示导航栏 */

  @keyframes float {
    0% {
      bottom:30px
    }
    50% {
      bottom: 35px;
    }
    100% {
      bottom: 30px;
    }
  }
  @keyframes stretch {
    0% {
      width:0;
    }
    100% {
      width:100%;
    }
  }
</style>